package nickthissen.iracing.parsing;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.ArrayUtils;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.Node;

public class Linq 
{
	public static <T> ArrayList<T> where(List<T> items, Predicate<T> predicate)
	{
		ArrayList<T> matches = new ArrayList<T>();
		for (T item : items)
		{
			if (predicate.apply(item)) matches.add(item);
		}
		return matches;
	}
	
	public static <T> boolean any(List<T> items, Predicate<T> predicate)
	{
		for (T item : items)
		{
			if (predicate.apply(item)) return true;
		}
		return false;
	}
	
	public static <T> T first(List<T> items, Predicate<T> predicate)
	{
		for (T item : items)
		{
			if (predicate.apply(item)) return item;
		}
		return null;
	}
	
	public static <T> T last(List<T> items, Predicate<T> predicate)
	{
		T match = null;
		for (T item : items) 
		{
			if (predicate.apply(item)) match = item;
		}
		return match;
	}
}
